<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport"
				content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>全国青少年电子信息智能创新大赛</title>
	<link rel="icon" href="./images/logo.png">
	<link rel="stylesheet" href="./lib/layui/css/modules/layer/default/layer.css">
	<link rel="stylesheet" href="./lib/layui/css/layui.css">
	<link rel="stylesheet" href="./css/game-details.css">
	<link rel="stylesheet" href="./lib/layui/css/modules/layer/default/layer.css">
	<link rel="stylesheet" type="text/css" href="./lib/formSelect/formSelects-v4.css"/>
	<script src="./lib/layui/layui.js"></script>
	<script src="./lib/layui/lay/modules/layer.js"></script>
</head>
<body>
<section class="wrapper" v-cloak>
	<common-header active-path="match-item.html"></common-header>
	<section class="content">
		<section class="top">
			<section class="container">
				<section class="breadcrumb">
					<img src="./images/loc.png" alt="">
					<section>
						赛项 > <a href="javascript:;">参赛详情</a>
					</section>
				</section>
				<section class="game-item">
					<section class="img" :style="{backgroundImage: 'url(' + gameInfo.tmatch.mainImg + ')'}">
						<section class="status" :class="{finish: currStatus !== 3}">{{ ['未开始', '已完结', '进行中'][currStatus - 1] }}</section>
					</section>
					<section class="details">
						<section class="title">
							{{ gameInfo.tmatch.theme }}
							<section class="tag">{{ gameInfo.tmatch.typeName }}</section>
						</section>
						<section class="text">
							{{ gameInfo.tmatch.introduction | substr }}
						</section>
						<section class="time">
							<section>
								<img src="./images/icons/time.png" alt="">
								{{ (gameInfo.tmatch.createTime || '').split('T')[0] }} - {{ (gameInfo.tmatch.endTime || '').split('T')[0] }}
							</section>
							<section>
								<section v-if="(step > 1 || currStatus === 2) && step !== 5" class="status">
									{{ statusText[step] }}
								</section>
								<a v-else-if="isRefuse" :href="'./team.html?id=' + gameInfo.tmatch.id" class="status active" @click="goTeam">
									{{ statusText[5] }}
								</a>
								<a v-else :href="'./team.html?id=' + gameInfo.tmatch.id" class="status active" @click="goTeam">
									{{ statusText[step] }}
								</a>
								<img class="tips-img" v-if="isRefuse" @click="showResult = true" src="./images/icons/tips.png" alt="">
							</section>
						</section>

					</section>
				</section>
				<section class="tabs">
					<a
						v-for="(item, index) in tabs"
						v-show="step > item.step || (step === 5 && item.step === 0)"
						:class="{active: currStep === item.step + 1}"
						href="javascript:;"
						@click="changeTab(item,index)"
					>
						{{ item.name }}
					</a>
				</section>
			</section>
		</section>
		<section class="game-details">
			<section class="container">
				<section class="tabs" v-if="currStep !== 2">
					<a
						href="javascript:;"
				   :class="{active: gameStage === tab.type}"
				   v-for="(tab,index) in gameTabs" :key="tab.type"
				   @click="gameStage = tab.type"
					>
						{{ tab.name }}
					</a>
				</section>
				<section v-show="currStep === 1" class="step-one step-item">
					<section v-if="currGameStage.notice" class="text" v-html="currGameStage.notice">
					</section>
					<Empty style="height: 500px; margin-top: 30px;" v-else text="参赛须知正在上传中哦"></Empty>
				</section>
				<section v-show="currStep === 2" class="step-two step-item">
					<section class="title">
						组队信息
						<a class="dissolution" v-if="isLeader" :class="{disabled: !canDissolution}"  @click="dissolution" href="javascript:;">解除队伍</a>
					</section>
					<section class="game-info">
						<section>
							<span class="name">赛区：</span>
							<span class="value">{{ teamInfo.zoneName }}</span>
							<span class="name">团队id：</span>
							<span class="value">{{ tuanduiid }}</span>
						</section>
						<section>
							<span class="name">参赛形式：</span>
							<span class="value">{{ isMulti ? '团队' : '个人' }}</span>
						</section>
						<section>
							<span class="name">组别：</span>
							<span class="value">{{ teamInfo.gradeName }}</span>
						</section>
						<section v-if="isMulti">
							<span class="name">团队名称：</span>
							<span class="value">{{ teamInfo.teamName }}</span>
						</section>
					</section>
					<section class="title">队员信息</section>
					<section class="member-list">
						<section class="member-item" v-for="user in userList">
							<section class="name">
								姓名：<span class="value">{{ user.memberName }}</span>
							</section>
							<section class="school">
								所在学校（就读学校）：<span class="value">{{ user.schoolName }}</span>
							</section>
						</section>
					</section>
					<section class="title">指导老师</section>
					<section class="game-info teacher-info">
						<section>
							<span class="name">姓名：</span>
							<span class="value">{{ teacher.memberName }}</span>
						</section>
						<section>
							<span class="name">工作单位：</span>
							<span class="value">{{ xuexiao }}</span>
						</section>
					</section>
				</section>
				<section v-show="currStep === 3" class="step-three step-item">
					<section class="game-types" v-if="currGameType !== 3">
						<section class="game-type-item" v-for="item in currGameTypes" @click="goExam(item)" v-show="!item.hide">
							<img :src="item.icon" alt="">
							<img class="active-icon" :src="item.activeIcon" alt="">
							<section class="title" v-if="item.itemName=='编程作品'">在线编程</section>
							<section class="title" v-else>{{ item.itemName }}</section>

							<section class="time">{{ formatTime(item.startTime) }}</section>
							<section class="time">{{ formatTime(item.endTime) }}</section>
						</section>
					</section>
					<section class="upload-works" v-if="currGameType === 3">
						<section class="radio">
							<a v-for="item in uploadFileTypes" :class="{active: item.type === uploadType}" href="javascript:;" @click="uploadType = item.type">{{ item.name }}</a>
						</section>
						<section class="upload-content">
							<label class="upload-tips">
								<img src="./images/icons/upload-icon.png" alt="">
								仅支持word、excel、ppt、可视化编程格式sb,sb2,sb3文件，zip，rar，mp4、jpg格式
								文档每队1个，视频1个，图片最多5个，文档类的不高5M，视频类的不高于50M（MP4），
								图片每个不超过1M
								<input :accept="fileTypeMap[uploadType]" type="file" style="display: none;" @change="uploadFile">
							</label>
							<section v-for="(file, index) in fileList" class="upload-item">
								<section class="name">
									<section>{{ file.name }}(<span class="status">{{ file.status === 100 ? '上传成功' : file.status + '%'}}</span>)</section>
									<img v-if="file.status === 100" @click="fileList.splice(index, 1)" src="./images/icons/delete-icon.png" alt="">
								</section>
								<section v-if="file.status !== 100" class="progress">
									<section :style="{width: file.status + '%'}" class="progress-bar"></section>
								</section>
							</section>
							<a href="javascript:;" class="submit-btn">提交</a>
						</section>
					</section>
				</section>
				<section v-show="currStep === 4" class="step-four step-item">
					<section class="result-info">
						<section v-if="gameStage === 1" class="result-item">
							<section class="top">
								<section class="title">
									<img src="./images/icons/score.png" alt="">
									初赛比赛成绩
								</section>
								<a href="javascript:;" class="download" @click="download">参赛证明下载</a>
							</section>
						</section>
						<section v-if="gameStage === 2" class="result-item">
							<section class="top">
								<section class="title">
									<img src="./images/icons/score.png" alt="">
									复赛比赛成绩
								</section>
							</section>
						</section>
						<section v-if="gameStage === 3" class="result-item">
							<section class="top">
								<section class="title">
									<img src="./images/icons/score.png" alt="">
									决赛比赛成绩
								</section>
								<section class="appeal-btn" v-if="isLeader">
									<a href="javascript:;" v-if="disabled" class="disabled">申诉？</a><a href="javascript:;" v-else @click="showAppealModal">申诉？</a>限比赛结果出来后2小时之内有效,<a :class="{disabled: disabled}" href="javascript:;" @click="getAppeal">查看结果</a>
								</section>
							</section>
						</section>
						<Empty v-if="isEmpty(scoreObj[currGameStage.id]) || (isEmpty(scoreObj[currGameStage.id].reportCart) && isEmpty(scoreObj[currGameStage.id].workScore))" text="成绩还未发布" class="score-empty"></Empty>
						<template v-else>
							<table class="layui-table" style="margin-bottom: 50px;" v-if="!isEmpty(scoreObj[currGameStage.id].reportCart)">
								<thead>
								<tr>
									<th v-for="head in paperHead">{{ head }}</th>
								</tr>
								</thead>
								<tbody>
								<tr v-for="item in scoreObj[currGameStage.id].reportCart">
									<td>{{ item.memberName }}</td>
									<td>{{ item.points }}</td>
									<td>{{ item.createTime }}</td>
								</tr>
								</tbody>
							</table>
							<table class="layui-table" v-if="!isEmpty(scoreObj[currGameStage.id].workScore)">
								<thead>
								<tr>
									<th v-for="head in workHead">{{ head }}</th>
								</tr>
								</thead>
								<tbody>
								<tr>
									<td>{{ scoreObj[currGameStage.id].workScore.score1 }}</td>
									<td>{{ scoreObj[currGameStage.id].workScore.score2 }}</td>
									<td>{{ scoreObj[currGameStage.id].workScore.score }}</td>
								</tr>
								</tbody>
							</table>
						</template>
						<section v-if="currGameStage.isView&&(tcheck!=1)&&jinjisaicheng>=thissaichengid" class="tips-text">您已确认参加下一场比赛</section>
						<section v-if="(isQuit==true)&&(tcheck==1)" class="tips-text">您已放弃参加下一场比赛</section>
						<!-- {{currGameStage.id}}  {{ teamInfo.scheduleId}}   {{isLeader}} {{levelUp}}  {{step}} -->
						<template v-if="step === 4 && levelUp === 1 && isLeader && currGameStage.id === teamInfo.scheduleId">
							<section class="tips">
								恭喜晋级，请在{{ formatTime(currGameStage.index === 0 ? gameInfo.fusaiTime : gameInfo.juesaiTime) }}之前回复组委会是否继续参若未在规定时间内回复则视为弃权   ！
							</section>
							<section class="btns">
								<a href="javascript:;" class="give-up" @click="giveUp">全队弃权</a>
								<a href="javascript:;" class="continue" @click="showModal = true">继续参赛</a>
							</section>
						</template>
					</section>
				</section>
			</section>
		</section>
		<common-modal
			title="审核失败"
			:visible.sync="showResult"
		>
			<section style="padding: 100px 0; text-align: center" class="desc" style="text-align: center">
				{{ refuseMsg || '暂未回复' }}
			</section>
		</common-modal>
		<common-modal
			title="继续参赛"
			:visible.sync="showModal"
		>
			<form class="layui-form" @submit.prevent>
				<section class="layui-form-item" style="height: auto; min-height: 54px;">
					<span><span class="required">*</span> 选择参赛人</span>
					<section>
						<select
							lay-verify="required"
							lay-reqtext="请选择参赛人"
							name="gameUsers"
							xm-select="select"
						>
<!--							<option v-for="item in userList" :value="item.memberId">{{ item.memberName }}</option>-->
						</select>
					</section>
				</section>
				<section class="layui-form-item">
					<span>更换作品提交人</span>
					<select name="submitUsers" id="teamuserdz">
						<option value="">请选择</option>
						<option v-for="item in userList" :value="item.userId">{{ item.memberName }}</option>
					</select>
				</section>
				<section class="tips">
					注：如需更换作品提交人，请选择
				</section>
				<button ref="changeSubmitUser" type="submit" lay-submit="" lay-filter="submit" style="display: none;"></button>
			</form>
			<template #footer>
				<a href="javascript:;" class="confirm-btn" @click="confirmGame">确定</a>
				<a href="javascript:;" class="cancel-btn" @click="showModal = false">取消</a>
			</template>
		</common-modal>
		<common-modal
			title="申诉"
			:visible.sync="showAppeal"
		>
			<textarea v-model="appealText" maxlength="200" class="appeal layui-textarea" placeholder="请输入申诉原因（请仔细确认申诉信息，提交后不可更改）"></textarea>
			<template #footer>
				<a href="javascript:;" @click="appeal">提交申诉</a>
			</template>
		</common-modal>
		<common-modal
			title="申诉结果"
			:visible.sync="showAppealResult"
		>
			<section class="desc">
				{{ appealResult }}
			</section>
		</common-modal>
	</section>
	<common-footer></common-footer>
</section>
<script src="./js/jquery.min.js"></script>
<script src="./lib/formSelect/formSelects-v4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="./js/vue.min.js"></script>
<script src="../js/abkj/slAjax.js"></script>
<script src="../js/abkj/match/api/webinfo.js"></script>
<script src="http://gosspublic.alicdn.com/aliyun-oss-sdk-6.4.0.min.js"></script>
<script src="../js/abkj/oss/app.js"></script>
<script src="../js/abkj/fun_tool.js"></script>
<script src="../js/abkj/match/api/tmatch.js"></script>
<script src="../js/abkj/ext/matchExt.js"></script>
<script src="../js/abkj/ext/signExt.js"></script>
<script src="../js/abkj/ext/news.js"></script>
<script src="./js/common.js"></script>
<script src="./components/index.js"></script>
<script>
function toTime(strTime) {

 if (!strTime) {
    return '';
 }
 var myDate = new Date(strTime );
 var d=new Date(strTime);
 var d1=Date.UTC(d.getUTCFullYear(),d.getUTCMonth() ,d.getUTCDate(),d.getUTCHours()-8,d.getUTCMinutes(),d.getUTCSeconds())
 myDate=new Date(d1);
 if (myDate == 'Invalid Date') {
  strTime = strTime.replace(/T/g, ' ');
  strTime = strTime.replace(/-/g, '/');
  strTime = strTime.replace(/\.\d+/, ' ');//去掉毫秒
  myDate = new Date(strTime );
 }
  	// alert(myDate)
 return myDate; //输出的也是带T时间格式，但在安卓和ios上时间保持一致
}
Date.prototype.Format = function(fmt)
    { //author: meizz
      var o = {
        "M+" : this.getMonth()+1,                 //月份
        "d+" : this.getDate(),                    //日
        "h+" : this.getHours(),                   //小时
        "m+" : this.getMinutes(),                 //分
        "s+" : this.getSeconds(),                 //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S"  : this.getMilliseconds()             //毫秒
      };
      if(/(y+)/.test(fmt))
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
      for(var k in o)
        if(new RegExp("("+ k +")").test(fmt))
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
      return fmt;
    }
	$(function () {
		var tool = fun_tool()
		var vm = new Vue({
			el: '.wrapper',
			data: {
				tuanduiid:'',
				roleTypeid:'',
				tcheck:0,
				programFinish:0,
         thissaichengid:0,

				isRefuse: false,//是否审核失败
				isQuit: false,//是否退出队伍
				showCertificate: false,
				showResult: false,
				isMulti: false,
				levelUp: false,
				disabled: true,//是否能申诉
				canDissolution: false,//是否能够解除队伍
				showAppeal: false,//申诉弹窗
				showAppealResult: false,//申诉结果弹窗
				signing: false, //报名状态,
				step: 1, //当前处于哪个阶段
				currStep: 1, //当前选中的哪个tab
				gameStage: 1,//比赛阶段， 初赛复赛决赛
				uploadType: 0,
				currGameType: 1,
				currStatus: '',
				paperHead: [],
				workScore: {},
				workHead: [],//表头
				reportCart: [],//成绩
				matchId: tool.getUrlParam('id'),
				appealText: '',//申诉文字
				appealResult: '',
				refuseMsg: '', //拒绝原因
				form: null,
				layer: null,
				jinjisaicheng:0,
				gameInfo: {
					chedulesList: [],
					tmatch: {
						createTime: '',
						endTime: '',
					}
				},
				userInfo: tool.getUserInfo(),
				teamInfo: {},
				teacher: {},
				userList: [],
				myhistory:[],
				xuexiao:"",

				statusText: {
					1: '组队报名',
					2: '报名审核中',
					3: '报名组队成功',
					4: '报名组队成功',
					6: '报名组队成功',
					5: '审核失败，请重新报名'
				},//报名状态
				uploadFileTypes: [
					{type: 0, name: '视频'},
					{type: 1, name: '图片'},
					{type: 2, name: '文档'},
				],
				fileTypeMap: ['video/mp4', 'image/jpeg', '.doc, .docx, .zip, .rar, .sb, .sb2, .sb3'],
				fileList: [
					// {name: '机器人编程课', url: 'xx', status: 100},
					// {name: '机器人编程课', url: 'xx', status: 10},
					// {name: '机器人编程课', url: 'xx', status: 55},
				],
				tabs: [
					{step: 0, name: '参赛须知'},
					{step: 1, name: '组队信息'},
					{step: 2, name: '参加比赛'},
					{step: 3, name: '比赛结果'},
				],
				scoreObj: {},
				showModal: false,
			},
			computed: {
				isLeader: function () {
				    if (this.userList.length==0){
						return true
					}
					if (!this.userList) return
					return this.userInfo && this.userInfo.id === (this.userList.filter(function (item) {
						return item.roleType === 2
					})[0] || {}).userId
				},
				gameTabs: function () {
					var list = this.gameInfo.chedulesList || []
					var index = list.map(function (item) {
						return item.schedule.id
					}).indexOf(this.teamInfo.scheduleId)
					if (!tool.getUserInfo() || !this.teamInfo.matchId) index = 0
					return list.slice(0, index + 1).map(function (item, itemIndex) {
						var schedule = item.schedule
						return {
							id: schedule.id,
							endTime: schedule.endTime,
							isView: itemIndex < index || list.length === 4,
							index: itemIndex,
							type: schedule.scheduleType,
							name: schedule.scheduleName,
							notice: schedule.notice,
							scheduleItem: item.scheduleItem || []
						}
					})
				},
				currGameStage: function () {
					var data = null
					var gameStage = this.gameStage

					// console.log(gameStage)
					this.gameTabs.forEach(function (item) {


						// alert(vm.tcheck)

						if (data) return
						if (item.type === gameStage){
							data = item
							try{
								var teamList=JSON.parse(localStorage.teamList1)
								var myuserid=localStorage.myuserid1
								var thissaichengid=item.id
								vm.thissaichengid=thissaichengid
								// alert(item.id)
								vm.tcheck=0
								console.log(JSON.stringify(vm.myhistory))
								for (i=0;i<vm.myhistory.length;i++){

										//  alert(teamList[i].memScheduleId)
										// alert(vm.myhistory[i].userId)
										//  alert(vm.myhistory[i].memScheduleId)
										// alert(myuserid)
										//  alert(thissaichengid)
										if (myuserid==vm.myhistory[i].userId){
											vm.jinjisaicheng=vm.myhistory[i].memScheduleId
										}
										if (myuserid==vm.myhistory[i].userId&&thissaichengid==vm.myhistory[i].memScheduleId){

											vm.tcheck=1
											break
										}
								}
							//  alert(vm.tcheck)
							}
							catch(error){

							}

						}
					})
					return data || {}
				},
				currGameTypes: function () {
					// scheduleItem
					var vm = this
					var icons = {
						1: {activeIcon: './images/icons/dati-active.png', icon: './images/icons/dati.png'},
						2: {activeIcon: './images/icons/biancheng-active.png', icon: './images/icons/biancheng.png'},
						3: {activeIcon: './images/icons/zuopin-active.png', icon: './images/icons/zuopin.png'},
						4: {activeIcon: './images/icons/bisai-active.png', icon: './images/icons/bisai.png'}
					}
					var gameTypes = [
						{id: 1, name: '在线答题', startTime: '2020/04/08 18:00:00', endTime: '2020/04/08 18:00:00', activeIcon: './images/icons/dati-active.png', icon: './images/icons/dati.png'},
						{id: 2, name: '在线编程', startTime: '2020/04/08 18:00:00', endTime: '2020/04/08 18:00:00', activeIcon: './images/icons/biancheng-active.png', icon: './images/icons/biancheng.png'},
						{id: 3, name: '作品提交', startTime: '2020/04/08 18:00:00', endTime: '2020/04/08 18:00:00', activeIcon: './images/icons/zuopin-active.png', icon: './images/icons/zuopin.png'},
						{id: 4, name: '现场比赛', startTime: '2020/04/08 18:00:00', endTime: '2020/04/08 18:00:00', activeIcon: './images/icons/bisai-active.png', icon: './images/icons/bisai.png'},
					]

					if (this.currGameStage.scheduleItem) {
						var leader = vm.userList.filter(function (item) {
							return item.roleType === 2
						})[0] || {}
						return this.currGameStage.scheduleItem.map(function (item) {
							item.activeIcon = icons[item.itemId].activeIcon
							if (item.itemId > 1 && vm.userInfo && vm.userInfo.id !== leader.userId) item.hide = true
							item.icon = icons[item.itemId].icon
							// vm.scoreObj[item.scheduleId] = {reportCart: [], workScore: {}}
							// alert(JSON.stringify(this.currGameTypes))
							return item
						})
					}
				}
			},
			mounted: function () {
				var date = +new Date()
				var vm = this
				// this.$refs.form.onsubmit = function () { return false}
				getMatchEntiry(tool.getUrlParam('id'), function (data) {
					vm.gameInfo = data
					vm.gameInfo.fusaiTime=vm.gameInfo.fusaiTime
					// alert(vm.gameInfo.juesaiTime)
					// vm.gameInfo.fusaiTime=new Date(toTime(vm.gameInfo.fusaiTime)).Format("yyyy-MM-dd hh:mm:ss")
					// alert(vm.gameInfo.fusaiTime )
					// vm.step = vm.gameInfo.tmatch.state + 1
					var startDate = +new Date(vm.gameInfo.tmatch.createTime)
					var endDate = +new Date(vm.gameInfo.tmatch.endTime)
					if (date < startDate) vm.currStatus = 1 //未开始
					else if (date > endDate) vm.currStatus = 2 //已结束
					else vm.currStatus = 3 //进行中
					vm.gameInfo.chedulesList = vm.gameInfo.chedulesList || []
					vm.isMulti = vm.gameInfo.tmatch.multiplayer === 1
					vm.canDissolution = +new Date() < +new Date(data.signEndTime)
					//!vm.step && (vm.step = vm.gameInfo.tmatch.state + 1)
				}, function (err) {})
				vm.userInfo && getTeamInfo(tool.getUrlParam('id'), function (data) {
					console.log(JSON.stringify(data))
					try{
						vm.tuanduiid=data.teamList[0].signupId
					}
					catch(error){

					}
                    
					// alert(data.teamList.signupId)
					var userinfo=tool.getUserInfo()
					localStorage.myuserid1=userinfo.id
					var teamList=data.teamList
					vm.myhistory=[]
					try{

						 for (i=0;i<data.history.length;i++){
							  for (j=0;j<data.history[i].reportCart.length;j++){
									   var json={}
										 json.userId=data.history[i].reportCart[j].userId
										 json.memScheduleId=data.history[i].reportCart[j].memScheduleId
                     vm.myhistory.push(json)

								}

						 }

					}
					catch(error){

					}

					console.log(JSON.stringify(vm.myhistory))
					console.log(JSON.stringify(teamList))
					try{
						for (i=0;i<data.teamList.length;i++){
						  if (localStorage.myuserid1==data.teamList[i].userId){
								vm.roleTypeid=data.teamList[i].roleType
								break
							}
					}
					}
					catch(error){
						
					}
					// alert(vm.roleTypeid)

          localStorage.teamList1=JSON.stringify(data.teamList)

                    // alert(JSON.stringify(data.teamList))
					vm.programFinish=data.programFinish
					if (data.historyState === 1) {
						vm.isRefuse = true
						return vm.refuseMsg = data.refuseMsg
					}
					if (data.teamInfo && data.teamInfo.matchId == vm.matchId) {

						vm.teamInfo = data.teamInfo
						// 通过teamList进行过滤到队员信息
						vm.userList = data.teamList.filter(function (item) {
							// alert(data.teamList)
							// roleType === 0 学生
							return  item.roleType === 0 || item.roleType === 2
						}).map(function (item) {
							item.isInTeam = item.state === 1 //根据state判断是否已经在队伍中
							item.isInvited = true
							item.name = item.memberName || ''
							item.school = item.schoolName || ''
							vm.xuexiao=item.schoolName
							// alert(vm.xuexiao)
							return item
						})
						layui.formSelects.data('select', 'local', {
							arr: vm.userList.map(function (item) {
								return {
									selected: true,
									name: item.name,
									value: item.userId
								}
							})
						})
						// 通过teamList进行过滤获取到教师信息
						vm.teacher = data.teamList.filter(function (item) {
							// roleType === 1 教师
							return item.roleType === 1
						}).map(function (item) {
							item.isInTeam = item.state === 1
							item.isInvited = true
							item.name = item.memberName || ''
							item.school = item.schoolName || ''
							return item
						})[0] || vm.teacher
						vm.step = data.teamInfo.state + 1
						vm.workHead = data.workHead || []
						vm.paperHead = data.paperHead || []
						vm.$set(vm.scoreObj, vm.teamInfo.scheduleId, {
							workScore: data.workScore || {},
							reportCart: data.reportCart || []
						})
						var userinfo=tool.getUserInfo()
					  localStorage.myuserid1=userinfo.id
						// alert(data.reportCart)

						localStorage.datidata=JSON.stringify(data.reportCart)
						vm.disabled = vm.isEmpty(data.workScore) || ((+new Date() - (+new Date(data.workScore.createTime))) / 1000 / 60 / 60) > 2
						if (data.history && data.history.length > 0) {
							data.history.forEach(function (item) {
								vm.$set(vm.scoreObj, item.scheduleId, {
									workScore: item.workScore || {},
									reportCart: item.reportCart || []
								})
							})
						}
						vm.levelUp = data.levelUp
						vm.isQuit = data.isQuit
						  // alert(vm.isQuit)
						if (data.workScore || data.reportCart || data.history.length > 0){
							vm.step = 4
						}
						// 步骤到第二步
					}else{
						vm.step=1
					}
				}, function () {})
				layui.use(['form', 'layer', 'table'], function () {
					vm.form = layui.form
					vm.layer = layui.layer
					vm.form.on('submit(submit)', function (data) {
						var json1={
							agree: 1,
							members: data.field.gameUsers.split(','),
							leaderId: document.getElementById("teamuserdz").value
						}
						//  alert(JSON.stringify(json1))
						signAgain({
							agree: 1,
							members: data.field.gameUsers.split(','),
							leaderId:document.getElementById("teamuserdz").value
						}, function () {
							layer.msg('继续参赛成功！', {icon: 1})
							setTimeout(function () {
								location.reload()
							}, 1500)
						})
					})
				})
			},
			methods: {
				goExam: function (item) {
					if (this.roleTypeid==1){
						alert("指导老师不能答题！")
						return false
					}

					var scheduleId=this.teamInfo.scheduleId
					var myuserid=localStorage.myuserid1
					var dtlist=JSON.parse(localStorage.datidata)
					// alert(myuserid)
					// alert(scheduleId)
					//  alert(JSON.stringify(dtlist))
					var ischecked=0
					try{
						for (i=0;i<dtlist.length;i++){
							  if (scheduleId==dtlist[i].memScheduleId&&myuserid==dtlist[i].userId){
								  ischecked=1
									break
								}
						}
					}
					catch(error){

					}


					var vm = this
					//  alert(new Date(Date.parse(vm.formatTime(item.endTime))).Format("yyyy-MM-dd hh:mm:ss")  )
					//  alert(new Date().Format("yyyy-MM-dd hh:mm:ss"))
					if (this.isQuit) return layer.msg('您已不在队伍中，无法进行此操作', {icon: 5})
					var hasGrade = this.scoreObj[this.currGameStage.id].workScore.score !== undefined || this.scoreObj[this.currGameStage.id].reportCart.length > 0
					if (item.itemId === 1 && ischecked==1) return layer.msg('您已参赛并交卷', {icon: 1})
				
				
          	if (new Date(item.endTime)  < new Date() ) return layer.msg('比赛时间已结束', {icon: 5})
					if (new Date(item.startTime) > new Date() ) return layer.msg('未到比赛时间', {icon: 5})

					if (item.itemId === 1) {
						return startAnswer('', function (url) {
							localStorage.url1=decodeURIComponent(url) + '&matchId=' + vm.matchId
							window.location='exam1.html'
						})
					}
					if (item.itemId === 4) {
						  //进入编程题比赛
							 console.log(JSON.stringify(vm.gameInfo ))
							localStorage.saixiang=vm.gameInfo.tmatch.theme
							localStorage.startTime=item.startTime
							localStorage.endTime=item.endTime
							//  alert(JSON.stringify(vm.teamInfo.id))
							localStorage.matchId=vm.teamInfo.matchId
							localStorage.zoneId=vm.teamInfo.zoneId
							localStorage.gradeId=vm.teamInfo.groupId
							localStorage.scheduleId=vm.teamInfo.scheduleId
							localStorage.myteamid=vm.teamInfo.id
							// alert(localStorage.scheduleId)
							var prjName="mgr_"

							localStorage.myusertoken=localStorage.getItem("token")
							// alert(localStorage.myusertoken)
							if (vm.programFinish==1||vm.programFinish=='1'){
								  alert("编程题已经交卷！")
									return false
							}
							//获取编程题列表

							startCoding({}, function (data) {
								// alert(JSON.stringify(data))
								localStorage.tilist=JSON.stringify(data)
								window.location="code-exam.html"
								//  alert(JSON.stringify(data))
							})

					}
					if (item.itemId === 2) {
						window.open('upload-files.html?id=' + this.matchId, '_blank')
					}
					// if (item.itemId === 2) return location.href = './code-exam.html?id=' + tool.getUrlParam('id')
				},
				changeTab: function (item) {
					this.currStep = item.step + 1
				},
				goTeam: function (e) {
					if (!this.userInfo) {
						this.$confirm({
							title: '您还未登陆，请您登录',
							success: function () {
								location.href = './login.html'
							}
						})
						e.preventDefault()
					}
				},
				dissolution: function () {
					if (!this.canDissolution) return
					// 解除队伍
					this.$confirm({
						title: '确认解除队伍吗？',
						success: function () {
							dismiss(function () {
								layer.msg('解除成功', {icon: 1})
								setTimeout(function () {
									location.reload()
								})
							})
						}
					})
				},
				isEmpty(obj) {
					if (!obj) return true
					if (typeof obj.length === 'number') return obj.length === 0
					var result = []
					for (var k in obj) {
						result.push(k)
					}
					return result.length === 0
				},
				confirmGame: function () {
					this.$refs.changeSubmitUser.click()
				},
				getAppeal: function () {
					if (this.disabled) return
					var vm = this
					getAppeal(function (data) {
						vm.showAppealResult = true
						vm.appealResult = data ? data.remark  : '请耐心等待回复'
					})
				},
				showAppealModal: function () {
					var vm = this
					getAppeal(function (data) {
						if (data && data.content) layer.msg('您已提交申诉。', {icon: 5})
						else vm.showAppeal = true
					})
				},
				appeal: function () {
					var vm = this
					if (!this.appealText.trim()) return layer.msg('请输入申诉内容', {icon: 2})
					addAppeal({content: this.appealText.trim()}, function () {
						layer.msg('提交申诉成功！', {icon: 1})
						setTimeout(function () {
							vm.showAppeal = false
							vm.appealText = ''
						}, 1500)
					})
					$.ajax({
						url: '',
						success: function () {

						}
					})
				},
				giveUp: function () {
					this.$confirm({
						// title: '您已弃权参加' + this.currGameStage.name,
						title: '您的队伍将放弃参赛资格',
						success: function () {
							signAgain({agree: 0}, function () {
								location.reload()
							})
						}
					})
				},
				download: function () {
					window.open('certificate.html?name=' + this.userInfo.name + '&theme=' + this.gameInfo.tmatch.theme, '_blank')
				},
				formatTime: function (time) {
					// alert(time)
					if (!time||time==''||time==undefined||time==null) return ''
					return time.split('T').join(' ')
				},
			}
		})
	})
</script>
</body>
</html>
